package com.newegg.datafeed.adserving.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.newegg.datafeed.adserving.request.LoginForm;
import com.newegg.datafeed.adserving.response.LoginInfo;
import com.newegg.datafeed.adserving.response.Response;
import com.newegg.datafeed.adserving.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags="用户接口")
@RestController
@RequestMapping("/api/login")
public class LoginAPI extends BaseAPI{
	
	@Autowired
	LoginService service;
	
	@ApiOperation(value="用户登录", consumes="application/json", produces="application/json")
    @RequestMapping(value="/in", method = RequestMethod.POST)
	@ResponseBody
    public Response<LoginInfo> login(@RequestBody LoginForm login) throws Exception {
		return SUCCESS(service.login(login.getUsername(), login.getPassword(), login.getType()));
    }
	
	@ApiOperation(value="用户退出登录", consumes="application/json", produces="application/json")
    @RequestMapping(value="/out", method = RequestMethod.POST)
	@ResponseBody
    public Response<Void> loginout() throws Exception {
		return SUCCESS();
    }
}
